<?php
/**
 * Created by PhpStorm.
 * User: wb-liuyuguang
 * Date: 14-5-19
 * Time: 下午12:47
 */
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>GitDeployer</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/bootstrap-responsiv.css">
    <link rel="stylesheet" type="text/css" href="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/dataTables.bootstra.css">
<style type="text/css">
    body{
        margin-top: 20px;
    }

    td pre{
        margin:0px ;
        padding: 0px ;
        border-width: 0px;
    }
</style>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
    <h1>GIT Deploy Tool</h1>
    <div id="msg" style="display:none" >
        <ul class="breadcrumb">
            <li>
                基本功能：
            </li>
        </ul>
    </div>
</div>
<div class="row-fluid">
<table class="table table-striped table-bordered table-hover datatable">
<thead>
<tr>
    <th>ID</th>
    <th>部署名称</th>
    <th>项目</th>
    <th>说明</th>
    <th>Website</th>
</tr>
</thead>
<tbody>
<?php
    for($i=1; $i<count($_SESSION['conf']); $i++){
        $rowType = "even gradeC";
        if( $i%2 == 0 ){
            $rowType = "odd gradeA";
        }
?>
        <tr class="<?php echo $rowType;?>" >
            <td><?php echo $i; ?></td>
            <td><?php echo $_SESSION['conf'][$i][0]; ?></td>
            <td><?php echo $_SESSION['conf'][$i][1]; ?></td>
            <td class="center"><pre><?php echo $_SESSION['conf'][$i][2]; ?></pre></td>
            <td class="center"><?php echo $_SESSION['conf'][$i][3]; ?></td>
        </tr>
<?php
    }
?>
</tbody>
</table>
</div>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/jquery.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/jquery.dataTables.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/bootstrap.min.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/238/n8vhm36h/dataTables.bootstrap.js"></script>
<script type="text/javascript" >
    function updateHint(txt){
        var li = $('#msg ul li')[0];
        li.innerHTML = txt;
        var msg = $('#msg')[0]
        msg.style.display = 'block';
    }

    function clickRow(e){
        var target = e.srcElement;
        if( target.nodeName == 'TD' ){
            var firstCell = target.parentElement.firstElementChild;
            var secondCell = firstCell.nextElementSibling;
            var id = firstCell.innerText;
            $.post('worker.php', { id: id }, function (text,status) {
                    updateHint('部署 <b>'+ secondCell.innerText + '</b> '+ text);
                });
            updateHint('正在部署 <b>'+ secondCell.innerText + '</b>...');
        }
    }
    function enableClick(){
        var rows = $('tr');
        for(var i=1; i<rows.length; i++){
            rows[i].addEventListener('click', clickRow);
        }
    }
    $(document).ready(function() {
        enableClick();
    } );
</script>
</div>
</body>
</html>